<%--
    Document   : realizar_reserva
    Created on : 10/10/2011, 20:06:46
    Author     : Carlos
--%>

<%@page import="model.Voo, model.Reserva, model.Usuario"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.util.List, java.util.Iterator, javax.servlet.http.HttpSession;"%>

<jsp:useBean id="Reserva" class="model.Reserva" scope="session" />


<!DOCTYPE html>
<html>
        <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" href="style.css" type="text/css" media="screen">
        <title>LISTA DE VOOS</title>
    </head>

    <jsp:include page="topologado.jsp"/>
    <body >
        <jsp:useBean id="usuario" class="model.Usuario" scope="session" />
        <jsp:useBean id="Voo" class="model.Voo" scope="session" />

        <%
                    HttpSession sessao = request.getSession(true);
                    try {
                        Usuario usuario1 = (Usuario) sessao.getAttribute("usuario");
                        if (usuario1.getCpf() == null) {
                            response.sendRedirect("login.jsp");
                        } else {
        %>

        <div id="content">
             <table style="text-align: left; width: 100%;" border="2" cellpadding="2" cellspacing="2" align="center">
            <tbody>
                <tr>
                    <td style="vertical-align: top; text-align: center;"><b>Numero do Voo</b></td>
                    <td style="vertical-align: top; text-align: center;"><b>Local de Origem</b></td>
                    <td style="vertical-align: top; text-align: center;"><b>Local de Destino</b></td>
                    <td style="vertical-align: top; text-align: center;"><b>Data</b></td>
                    <td style="vertical-align: top; text-align: center;"><b>Hora</b></td>
                    <td style="vertical-align: top; text-align: center;"><b>Reservar</b></td>
                </tr>
                <%
                    List listVoos = (List)request.getAttribute("listVoos");
                            for (Iterator i = listVoos.iterator(); i.hasNext();) {
                            Voo v = (Voo)i.next();
                %>
                <tr>
                    <td style="vertical-align: top; text-align: center;"><%= v.getNumVoo() %></td>
                    <td style="vertical-align: top; text-align: center;"><%= v.getLocalOrigem() %></td>
                    <td style="vertical-align: top; text-align: center;"><%= v.getLocalDestino() %></td>
                    <td style="vertical-align: top; text-align: center;"><%= v.getData() %></td>
                    <td style="vertical-align: top; text-align: center;"><%= v.getHora() %></td>
                    <td style="vertical-align: top; text-align: center;">
                        <a href="controlador?cmd=salvarReserva&numVooReserva=<%= v.getNumVoo()%>&idUser=<%= usuario.getId()%>">Reserve</a>
                    </td>
                </tr>
                <%
                    }
                %>
            </tbody>
        </table>
             <%
                                }
                            } catch (Exception e) {
                                e.printStackTrace();
                                response.sendRedirect("login.jsp");
                            }

                %>
        </div>
    </body>
    <jsp:include page="rodape.jsp"/>
</html>
